home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / Patterned Curve ƒ / patterned curve.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  4.3 KB  |  145 lines  |  [TEXT/KAHL]

  1. /*
  2.     patterned curve.c
  3.     
  4.     This file contains the calls to create a "thick" curve and fill it will a "star" as the pattern.
  5.         
  6.     NOTES:
  7.     • This file requires the new "GX"-ified interface files and libraries. With the interface files, all types and function
  8.     names are proceeded by a "gx" for types or "GX" for function names.
  9.     
  10.     • This file requires the following files to run correctly:
  11.         "graphics shell.c",  "ColorLibrary.c", "GraphicsDebugLibrary.c", "ShapeLibrary.c", "TransformLibrary.c".
  12.         
  13.     • This file prints the "best" in landscape mode.
  14.     
  15.     Change History:
  16.  
  17.        4/96    bob        Updated #includes to support changed GX Library names.
  18.                     Updated the note regarding the files needed to run.
  19.                     Updated the copyright date.
  20.  
  21.     ©1992 - 1996  Apple Computer, Inc.
  22.     All rights reserved.
  23. */
  24.  
  25. #include <events.h>
  26. #include <windows.h>
  27.  
  28. #include "FontLibrary.h"
  29. #include <GXErrors.h>
  30. #include "GraphicsLibraries.h"
  31. #include <GXEnvironment.h>
  32. #include "graphics shell.h"
  33.  
  34. //
  35. //  Set up the title and size of the window 
  36. //
  37. Str255     gWindowTitle = "\p Patterned Curve";
  38. Rect         gWindowQDRect  = {50, 20, 235, 375};
  39.  
  40. //
  41. //    gGraphicsHeapSize sets the size of the graphics heap created by calling the NewGraphicsClient routine
  42. //    in main () within graphics shell.c.  You can determine the amount of graphics heap required by using GraphicsBug.
  43. //    With  gGraphicsHeapSize set to 25k, I had 3 free blocks left in the graphics heap. Sounds good to me.
  44. //
  45. long        gGraphicsHeapSize = 25;
  46.  
  47. gxShape     gShape;
  48.  
  49. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  50.  
  51. void DoInitialization(gWindow)
  52. WindowPtr gWindow;
  53. {
  54.     gxCurve             curveGeometry = {ff(25), ff(125), ff(100), 0, ff(225), ff(125)};    
  55.     gxShape            starShape, testRect;
  56.     gxRectangle        starShapeBounds;
  57.     gxPatternRecord    starPattern;
  58.     
  59.     long starGeometry[] = {1, //  number of contours
  60.                         5, //  number of points 
  61.                           ff(60), 0, ff(90), ff(90),  ff(0), ff(30),  ff(120), ff(30), ff(0), ff(90)};   //  the points
  62.      
  63.      InitCommonColors();
  64.  
  65.     gShape = GXNewCurve (&curveGeometry);
  66.     
  67.     //
  68.     // Create a star gxShape which will be used as the fill pattern
  69.     //
  70.     starShape =  GXNewPolygons((gxPolygons *) starGeometry);
  71.      GXScaleShape(starShape, fl(0.25), fl(0.25), 0, 0);
  72.  
  73.     //
  74.     //    Get the bounds of our star gxShape.  We use the bounds to setup the u and v vectors of the pattern 
  75.     //    record. We want "gShape" to be filled  with the star where each star is placed at edge of the
  76.     //    previous star (i.e so the pattern's do not overlap).
  77.     //    
  78.      GXGetShapeBounds(starShape, 0L, &starShapeBounds);
  79.  
  80.     starPattern.u.x = 0;
  81.     starPattern.u.y = starShapeBounds.bottom;
  82.      starPattern.v.x = starShapeBounds.right + fixed1;
  83.     starPattern.v.y = 0;
  84.  
  85.     starPattern.attributes = gxPortAlignPattern;
  86.     starPattern.pattern = starShape;
  87.  
  88.     GXSetShapePattern(gShape, &starPattern);
  89.     
  90.     //
  91.     //    We can dispose of our star gxShape because it is now referenced from within the
  92.     //    pattern record contained in "gShape".
  93.     //
  94.      GXDisposeShape (starShape);
  95.     
  96.     SetShapeCommonColor (gShape, blue);
  97.     GXSetShapePen (gShape, ff(75));
  98.     GXMoveShape (gShape,  ff(50), 0);
  99. }
  100.  
  101. /*------ DoClick ---------------------------------------------------------------------------------------*/
  102.  
  103. void DoClick( orgMouseLoc, theWindow )
  104. gxPoint        orgMouseLoc;
  105. WindowPtr     theWindow;
  106. {
  107. }
  108.  
  109.  
  110. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  111.  
  112. void DoDraw(gWindow)
  113. WindowPtr gWindow;
  114. {
  115.     GXDrawShape (gShape);
  116. }
  117.  
  118.  
  119. /*------ DoDispose -------------------------------------------------------------------------------------*/
  120.  
  121. void DoDispose(gWindow)
  122. WindowPtr gWindow;
  123. {
  124.     /**  
  125.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  126.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  127.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  128.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  129.         can turn notices on in this file by setting gDebugging = TRUE (above).
  130.     **/
  131.     GXDisposeShape(gShape);  
  132.      GXDisposeShape(gWindowBoundsShape);  
  133.        DisposeCommonColors();
  134.        DisposeWindow(gWindow);
  135. }
  136.     
  137.  
  138.  
  139. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  140.  
  141. void DoIdle(gWindow)
  142. WindowPtr gWindow;
  143. {
  144. }
  145.